From 3175434ae4b9b071a7471d103983eb36ff79e740 Mon Sep 17 00:00:00 2001 From: Hollis Blanchard Date: Thu, 30 Nov 2006 15:26:55 -0600 Subject: [PATCH] [XEN][POWERPC] Clean up debug/traceback/trapping logic This patch tries to sort out all the debugging mechanisms we have available to us. Signed-off-by: Jimi Xenidis Signed-off-by: Hollis Blanchard --- xen/arch/powerpc/backtrace.c | 18 ++++++-- xen/arch/powerpc/exceptions.c | 34 +++++++------- xen/arch/powerpc/mm.c | 1 - xen/arch/powerpc/powerpc64/ppc970.c | 1 + .../misc.h => arch/powerpc/powerpc64/scom.h} | 28 +++++++----- xen/arch/powerpc/powerpc64/traps.c | 4 -- xen/arch/powerpc/setup.c | 2 +- xen/arch/powerpc/smp.c | 2 +- xen/arch/powerpc/time.c | 2 +- xen/arch/powerpc/usercopy.c | 1 + xen/include/asm-powerpc/debugger.h | 45 +++++++++++++------ xen/include/asm-powerpc/flushtlb.h | 1 - xen/include/asm-powerpc/mm.h | 1 - xen/include/asm-powerpc/page.h | 1 - xen/include/asm-powerpc/processor.h | 10 ----- 15 files changed, 84 insertions(+), 67 deletions(-) rename xen/{include/asm-powerpc/misc.h => arch/powerpc/powerpc64/scom.h} (51%) diff --git a/xen/arch/powerpc/backtrace.c b/xen/arch/powerpc/backtrace.c index 0ea2b679de..02333bb2e4 100644 --- a/xen/arch/powerpc/backtrace.c +++ b/xen/arch/powerpc/backtrace.c @@ -14,6 +14,7 @@ #include #include #include +#include static char namebuf[KSYM_NAME_LEN+1]; @@ -192,6 +193,19 @@ void show_backtrace(ulong sp, ulong lr, ulong pc) console_end_sync(); } +void show_backtrace_regs(struct cpu_user_regs *regs) +{ + console_start_sync(); + + show_registers(regs); + printk("dar 0x%016lx, dsisr 0x%08x\n", mfdar(), mfdsisr()); + printk("hid4 0x%016lx\n", regs->hid4); + printk("---[ backtrace ]---\n"); + show_backtrace(regs->gprs[1], regs->lr, regs->pc); + + console_end_sync(); +} + void __warn(char *file, int line) { ulong sp; @@ -202,9 +216,7 @@ void __warn(char *file, int line) sp = (ulong)__builtin_frame_address(0); lr = (ulong)__builtin_return_address(0); - backtrace(sp, lr, lr); + console_end_sync(); } - - diff --git a/xen/arch/powerpc/exceptions.c b/xen/arch/powerpc/exceptions.c index 3ba5dd0725..136b47c640 100644 --- a/xen/arch/powerpc/exceptions.c +++ b/xen/arch/powerpc/exceptions.c @@ -25,8 +25,10 @@ #include #include #include +#include #include #include +#include #undef DEBUG @@ -56,25 +58,19 @@ void do_dec(struct cpu_user_regs *regs) void program_exception(struct cpu_user_regs *regs, unsigned long cookie) { -#ifdef CRASH_DEBUG - __trap_to_gdb(regs, cookie); -#else /* CRASH_DEBUG */ - int recover = 0; - - console_start_sync(); - - show_registers(regs); - printk("dar 0x%016lx, dsisr 0x%08x\n", mfdar(), mfdsisr()); - printk("hid4 0x%016lx\n", regs->hid4); - printk("---[ backtrace ]---\n"); - show_backtrace(regs->gprs[1], regs->lr, regs->pc); - - if (cookie == 0x200) - recover = cpu_machinecheck(regs); + if (cookie == 0x200) { + if (cpu_machinecheck(regs)) + return; - if (!recover) - panic("%s: 0x%lx\n", __func__, cookie); - - console_end_sync(); + printk("%s: machine check\n", __func__); + } else { +#ifdef CRASH_DEBUG + if (__trap_to_gdb(regs, cookie) == 0) + return; #endif /* CRASH_DEBUG */ + + printk("%s: type: 0x%lx\n", __func__, cookie); + show_backtrace_regs(regs); + } + machine_halt(); } diff --git a/xen/arch/powerpc/mm.c b/xen/arch/powerpc/mm.c index 1df18669d3..a71bb8c2f8 100644 --- a/xen/arch/powerpc/mm.c +++ b/xen/arch/powerpc/mm.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include diff --git a/xen/arch/powerpc/powerpc64/ppc970.c b/xen/arch/powerpc/powerpc64/ppc970.c index e59571bd35..eacbf4ea0f 100644 --- a/xen/arch/powerpc/powerpc64/ppc970.c +++ b/xen/arch/powerpc/powerpc64/ppc970.c @@ -30,6 +30,7 @@ #include #include #include +#include "scom.h" #undef DEBUG #undef SERIALIZE diff --git a/xen/include/asm-powerpc/misc.h b/xen/arch/powerpc/powerpc64/scom.h similarity index 51% rename from xen/include/asm-powerpc/misc.h rename to xen/arch/powerpc/powerpc64/scom.h index b3ec14d44e..a68651f9ea 100644 --- a/xen/include/asm-powerpc/misc.h +++ b/xen/arch/powerpc/powerpc64/scom.h @@ -13,21 +13,27 @@ * along with this program; if not, write to the Free Software * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (C) IBM Corp. 2005 + * Copyright (C) IBM Corp. 2006 * - * Authors: Hollis Blanchard + * Authors: Jimi Xenidis */ -#ifndef _ASM_MISC_H_ -#define _ASM_MISC_H_ +#ifndef _ARCH_POWERPC_POWERPC64_SCOM_H_ +#define _ARCH_POWERPC_POWERPC64_SCOM_H_ -static inline void unimplemented(void) -{ -} +extern void cpu_scom_init(void); +int cpu_scom_read(unsigned int addr, unsigned long *d); +int cpu_scom_write(unsigned int addr, unsigned long d); +void cpu_scom_AMCR(void); -static inline void trap(void) -{ - asm volatile("trap"); -} +/* SCOMC addresses are 16bit but we are given 24 bits in the + * books. The low oerder 8 bits are some kinda parity thin and should + * be ignored */ +#define SCOM_AMC_REG 0x022601 +#define SCOM_AMC_AND_MASK 0x022700 +#define SCOM_AMC_OR_MASK 0x022800 +#define SCOM_CMCE 0x030901 +#define SCOM_PMCR 0x400801 +#define SCOM_PTSR 0x408001 #endif diff --git a/xen/arch/powerpc/powerpc64/traps.c b/xen/arch/powerpc/powerpc64/traps.c index e1945faa27..de29215d06 100644 --- a/xen/arch/powerpc/powerpc64/traps.c +++ b/xen/arch/powerpc/powerpc64/traps.c @@ -48,7 +48,3 @@ void show_registers(struct cpu_user_regs *regs) console_end_sync(); } -void show_execution_state(struct cpu_user_regs *regs) -{ - show_registers(regs); -} diff --git a/xen/arch/powerpc/setup.c b/xen/arch/powerpc/setup.c index 5c839f698e..56908502de 100644 --- a/xen/arch/powerpc/setup.c +++ b/xen/arch/powerpc/setup.c @@ -414,7 +414,7 @@ void __init __start_xen_ppc( } else { /* booted by someone else that hopefully has a trap handler */ - trap(); + __builtin_trap(); } __start_xen(mbi); diff --git a/xen/arch/powerpc/smp.c b/xen/arch/powerpc/smp.c index 937b1c59c2..ce3762960e 100644 --- a/xen/arch/powerpc/smp.c +++ b/xen/arch/powerpc/smp.c @@ -18,10 +18,10 @@ * Authors: Hollis Blanchard */ -#include #include #include #include +#include int smp_num_siblings = 1; int smp_num_cpus = 1; diff --git a/xen/arch/powerpc/time.c b/xen/arch/powerpc/time.c index 184e07e54d..04eaff1595 100644 --- a/xen/arch/powerpc/time.c +++ b/xen/arch/powerpc/time.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #define Dprintk(x...) printk(x) diff --git a/xen/arch/powerpc/usercopy.c b/xen/arch/powerpc/usercopy.c index d653ed1a05..bb96d23b3c 100644 --- a/xen/arch/powerpc/usercopy.c +++ b/xen/arch/powerpc/usercopy.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/xen/include/asm-powerpc/debugger.h b/xen/include/asm-powerpc/debugger.h index 7e284bf1d3..9c9d94b021 100644 --- a/xen/include/asm-powerpc/debugger.h +++ b/xen/include/asm-powerpc/debugger.h @@ -21,6 +21,38 @@ #ifndef _ASM_DEBUGGER_H_ #define _ASM_DEBUGGER_H_ +extern void show_backtrace_regs(struct cpu_user_regs *); +extern void show_backtrace(ulong sp, ulong lr, ulong pc); + +static inline void dump_execution_state(void) +{ + ulong sp; + ulong lr; + + sp = (ulong)__builtin_frame_address(0); + lr = (ulong)__builtin_return_address(0); + + show_backtrace(sp, lr, lr); +} + +static inline void debugger_trap_immediate(void) +{ + dump_execution_state(); + __builtin_trap(); +} + +static inline void show_execution_state(struct cpu_user_regs *regs) +{ + show_registers(regs); +} + +extern void __warn(char *file, int line); +#define WARN() __warn(__FILE__, __LINE__) +#define WARN_ON(_p) do { if (_p) WARN(); } while ( 0 ) +#define unimplemented() WARN() + +#define FORCE_CRASH() debugger_trap_immediate() + #ifdef CRASH_DEBUG #include @@ -32,8 +64,6 @@ static inline int debugger_trap_fatal( return vector; } -#define debugger_trap_immediate() __asm__ __volatile__ ("trap"); - #else /* CRASH_DEBUG */ static inline int debugger_trap_fatal( @@ -43,17 +73,6 @@ static inline int debugger_trap_fatal( return vector; } -static inline void debugger_trap_immediate(void) -{ - ulong sp; - ulong lr; - - sp = (ulong)__builtin_frame_address(0); - lr = (ulong)__builtin_return_address(0); - - show_backtrace(sp, lr, lr); -} - #endif /* CRASH_DEBUG */ #endif diff --git a/xen/include/asm-powerpc/flushtlb.h b/xen/include/asm-powerpc/flushtlb.h index c33926a3ae..222dc08d91 100644 --- a/xen/include/asm-powerpc/flushtlb.h +++ b/xen/include/asm-powerpc/flushtlb.h @@ -24,7 +24,6 @@ #include #include #include -#include /* The current time as shown by the virtual TLB clock. */ extern u32 tlbflush_clock; diff --git a/xen/include/asm-powerpc/mm.h b/xen/include/asm-powerpc/mm.h index 7d085c9dd4..094945e2fe 100644 --- a/xen/include/asm-powerpc/mm.h +++ b/xen/include/asm-powerpc/mm.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/include/asm-powerpc/page.h b/xen/include/asm-powerpc/page.h index f3fbaeb1ad..279cfbb2ab 100644 --- a/xen/include/asm-powerpc/page.h +++ b/xen/include/asm-powerpc/page.h @@ -28,7 +28,6 @@ #ifndef __ASSEMBLY__ #include -#include #include #define PFN_DOWN(x) ((x) >> PAGE_SHIFT) diff --git a/xen/include/asm-powerpc/processor.h b/xen/include/asm-powerpc/processor.h index d7a2965154..7d15847b09 100644 --- a/xen/include/asm-powerpc/processor.h +++ b/xen/include/asm-powerpc/processor.h @@ -38,10 +38,7 @@ struct domain; struct vcpu; struct cpu_user_regs; extern int cpu_machinecheck(struct cpu_user_regs *); -extern void cpu_scom_init(void); extern void show_registers(struct cpu_user_regs *); -extern void show_execution_state(struct cpu_user_regs *); -extern void show_backtrace(ulong sp, ulong lr, ulong pc); extern unsigned int cpu_extent_order(void); extern unsigned int cpu_default_rma_order_pages(void); extern int cpu_rma_valid(unsigned int log); @@ -54,13 +51,6 @@ extern void load_cpu_sprs(struct vcpu *); extern void flush_segments(void); extern void dump_segments(int valid); -/* XXX this could also land us in GDB */ -#define dump_execution_state() BUG() - -extern void __warn(char *file, int line); -#define WARN() __warn(__FILE__, __LINE__) -#define WARN_ON(_p) do { if (_p) WARN(); } while ( 0 ) - #define ARCH_HAS_PREFETCH static inline void prefetch(const void *x) {;} -- 2.30.2